import { http, Method } from "@/utils/request.js";

/**
 * 申请提现
 * @param {Object} data 提现申请数据
 * @param {number} data.amount 提现金额
 * @param {string} data.withdrawMethod 提现方式 (wechat|alipay|bank)
 * @param {Object} data.accountInfo 账户信息
 * @param {string} data.accountInfo.accountName 收款人姓名
 * @param {string} data.accountInfo.accountNumber 账户号码
 */
export function applyWithdraw(data) {
  return http.request({
    url: '/users/withdraw/apply',
    method: Method.POST,
    data
  });
}

/**
 * 获取提现记录列表
 * @param {Object} params 查询参数
 * @param {number} params.page 页码
 * @param {number} params.limit 每页数量
 * @param {string} params.status 状态筛选
 */
export function getWithdrawList(params) {
  return http.request({
    url: '/users/withdraw/records',
    method: Method.GET,
    data: params
  });
}

/**
 * 获取提现详情
 * @param {string} withdrawId 提现记录ID
 */
export function getWithdrawDetail(withdrawId) {
  return http.request({
    url: `/users/withdraw/${withdrawId}/detail`,
    method: Method.GET
  });
}

/**
 * 查询微信提现状态
 * @param {string} withdrawId 提现记录ID
 */
export function queryWechatWithdrawStatus(withdrawId) {
  return http.request({
    url: `/users/withdraw/${withdrawId}/wechat-status`,
    method: Method.GET
  });
}

/**
 * 获取提现统计
 */
export function getWithdrawStats() {
  return http.request({
    url: '/users/withdraw/stats',
    method: Method.GET
  });
}

/**
 * 取消提现申请
 * @param {string} withdrawId 提现记录ID
 */
export function cancelWithdraw(withdrawId) {
  return http.request({
    url: `/users/withdraw/${withdrawId}/cancel`,
    method: Method.POST
  });
}

/**
 * 重新申请提现
 * @param {string} withdrawId 提现记录ID
 */
export function retryWithdraw(withdrawId) {
  return http.request({
    url: `/users/withdraw/retry/${withdrawId}`,
    method: Method.POST
  });
}

/**
 * 更新用户订阅状态
 * @param {Object} data 订阅数据
 * @param {string} data.userId 用户ID
 * @param {boolean} data.withdrawNotification 是否订阅提现通知
 */
export function updateUserSubscription(data) {
  return http.request({
    url: '/users/subscription/update',
    method: Method.POST,
    data
  });
}

/**
 * 获取提现配置（手续费、限额等）
 */
export function getWithdrawConfig() {
  return http.request({
    url: '/users/withdraw/config',
    method: Method.GET
  });
}

/**
 * 确认收款
 * @param {string} withdrawId 提现记录ID
 */
export function confirmWithdrawReceipt(withdrawId) {
  return http.request({
    url: `/users/withdraw/${withdrawId}/confirm-receipt`,
    method: Method.POST
  });
}

/**
 * 获取未确认收款的提现记录
 */
export function getUnconfirmedWithdrawals() {
  return http.request({
    url: '/users/withdraw/unconfirmed',
    method: Method.GET
  });
}

/**
 * 批量确认收款
 * @param {Array} withdrawIds 提现记录ID数组
 */
export function batchConfirmWithdrawReceipt(withdrawIds) {
  return http.request({
    url: '/users/withdraw/batch-confirm-receipt',
    method: Method.POST,
    data: { withdrawIds }
  });
}

/**
 * 获取提现通知设置
 */
export function getWithdrawNotificationSettings() {
  return http.request({
    url: '/users/withdraw/notification-settings',
    method: Method.GET
  });
}

/**
 * 更新提现通知设置
 * @param {Object} settings 通知设置
 * @param {boolean} settings.websocket 是否接收WebSocket通知
 * @param {boolean} settings.stationMessage 是否接收站内信
 * @param {boolean} settings.wechatTemplate 是否接收微信模板消息
 */
export function updateWithdrawNotificationSettings(settings) {
  return http.request({
    url: '/users/withdraw/notification-settings',
    method: Method.PUT,
    data: settings
  });
} 